home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-4 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  50.7 KB  |  1,339 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Equality Predicates,  Prev: Type Predicates,  Up: Lisp Data Types
  46.  
  47. Equality Predicates
  48. ===================
  49.  
  50.    Here we describe two functions that test for equality between any two
  51. objects.  Other functions test equality between objects of specific
  52. types, e.g., strings.  For these predicates, see the appropriate chapter
  53. describing the data type.
  54.  
  55.  - Function: eq OBJECT1 OBJECT2
  56.      This function returns `t' if OBJECT1 and OBJECT2 are the same
  57.      object, `nil' otherwise.  The "same object" means that a change in
  58.      one will be reflected by the same change in the other.
  59.  
  60.      `eq' returns `t' if OBJECT1 and OBJECT2 are integers with the same
  61.      value.  Also, since symbol names are normally unique, if the
  62.      arguments are symbols with the same name, they are `eq'.  For
  63.      other types (e.g., lists, vectors, strings), two arguments with
  64.      the same contents or elements are not necessarily `eq' to each
  65.      other: they are `eq' only if they are the same object.
  66.  
  67.      (The `make-symbol' function returns an uninterned symbol that is
  68.      not interned in the standard `obarray'.  When uninterned symbols
  69.      are in use, symbol names are no longer unique.  Distinct symbols
  70.      with the same name are not `eq'.  *Note Creating Symbols::.)
  71.  
  72.           (eq 'foo 'foo)
  73.                => t
  74.           
  75.           (eq 456 456)
  76.                => t
  77.           
  78.           (eq "asdf" "asdf")
  79.                => nil
  80.           
  81.           (eq '(1 (2 (3))) '(1 (2 (3))))
  82.                => nil
  83.           
  84.           (setq foo '(1 (2 (3))))
  85.                => (1 (2 (3)))
  86.           (eq foo foo)
  87.                => t
  88.           (eq foo '(1 (2 (3))))
  89.                => nil
  90.           
  91.           (eq [(1 2) 3] [(1 2) 3])
  92.                => nil
  93.           
  94.           (eq (point-marker) (point-marker))
  95.                => nil
  96.  
  97.  
  98.  - Function: equal OBJECT1 OBJECT2
  99.      This function returns `t' if OBJECT1 and OBJECT2 have equal
  100.      components, `nil' otherwise.  Whereas `eq' tests if its arguments
  101.      are the same object, `equal' looks inside nonidentical arguments
  102.      to see if their elements are the same.  So, if two objects are
  103.      `eq', they are `equal', but the converse is not always true.
  104.  
  105.           (equal 'foo 'foo)
  106.                => t
  107.           
  108.           (equal 456 456)
  109.                => t
  110.           
  111.           (equal "asdf" "asdf")
  112.                => t
  113.           (eq "asdf" "asdf")
  114.                => nil
  115.           
  116.           (equal '(1 (2 (3))) '(1 (2 (3))))
  117.                => t
  118.           (eq '(1 (2 (3))) '(1 (2 (3))))
  119.                => nil
  120.           
  121.           (equal [(1 2) 3] [(1 2) 3])
  122.                => t
  123.           (eq [(1 2) 3] [(1 2) 3])
  124.                => nil
  125.           
  126.           (equal (point-marker) (point-marker))
  127.                => t
  128.           
  129.           (eq (point-marker) (point-marker))
  130.                => nil
  131.  
  132.      Comparison of strings is case-sensitive and takes account of text
  133.      properties as well as the characters in the strings.  To compare
  134.      two strings' characters without comparing their text properties,
  135.      use `string=' (*note Text Comparison::.).
  136.  
  137.           (equal "asdf" "ASDF")
  138.                => nil
  139.  
  140.      Two distinct buffers are never `equal', even if their contents are
  141.      the same.
  142.  
  143.    The test for equality is implemented recursively, and circular lists
  144. may therefore cause infinite recursion (leading to an error).
  145.  
  146. 
  147. File: lispref.info,  Node: Numbers,  Next: Strings and Characters,  Prev: Lisp Data Types,  Up: Top
  148.  
  149. Numbers
  150. *******
  151.  
  152.    XEmacs supports two numeric data types: "integers" and "floating
  153. point numbers".  Integers are whole numbers such as -3, 0, 7, 13, and
  154. 511.  Their values are exact.  Floating point numbers are numbers with
  155. fractional parts, such as -4.5, 0.0, or 2.71828.  They can also be
  156. expressed in exponential notation: 1.5e2 equals 150; in this example,
  157. `e2' stands for ten to the second power, and is multiplied by 1.5.
  158. Floating point values are not exact; they have a fixed, limited amount
  159. of precision.
  160.  
  161. * Menu:
  162.  
  163. * Integer Basics::            Representation and range of integers.
  164. * Float Basics::          Representation and range of floating point.
  165. * Predicates on Numbers::     Testing for numbers.
  166. * Comparison of Numbers::     Equality and inequality predicates.
  167. * Numeric Conversions::          Converting float to integer and vice versa.
  168. * Arithmetic Operations::     How to add, subtract, multiply and divide.
  169. * Rounding Operations::       Explicitly rounding floating point numbers.
  170. * Bitwise Operations::        Logical and, or, not, shifting.
  171. * Math Functions::            Trig, exponential and logarithmic functions.
  172. * Random Numbers::            Obtaining random integers, predictable or not.
  173.  
  174. 
  175. File: lispref.info,  Node: Integer Basics,  Next: Float Basics,  Up: Numbers
  176.  
  177. Integer Basics
  178. ==============
  179.  
  180.    The range of values for an integer depends on the machine.  The
  181. minimum range is -134217728 to 134217727 (28 bits; i.e.,
  182.  
  183.    -2**27 to
  184.  
  185.    2**27 - 1), but some machines may provide a wider range.  Many
  186. examples in this chapter assume an integer has 28 bits.
  187.  
  188.    The Lisp reader reads an integer as a sequence of digits with
  189. optional initial sign and optional final period.
  190.  
  191.       1               ; The integer 1.
  192.       1.              ; The integer 1.
  193.      +1               ; Also the integer 1.
  194.      -1               ; The integer -1.
  195.       268435457       ; Also the integer 1, due to overflow.
  196.       0               ; The integer 0.
  197.      -0               ; The integer 0.
  198.  
  199.    To understand how various functions work on integers, especially the
  200. bitwise operators (*note Bitwise Operations::.), it is often helpful to
  201. view the numbers in their binary form.
  202.  
  203.    In 28-bit binary, the decimal integer 5 looks like this:
  204.  
  205.      0000  0000 0000  0000 0000  0000 0101
  206.  
  207. (We have inserted spaces between groups of 4 bits, and two spaces
  208. between groups of 8 bits, to make the binary integer easier to read.)
  209.  
  210.    The integer -1 looks like this:
  211.  
  212.      1111  1111 1111  1111 1111  1111 1111
  213.  
  214. -1 is represented as 28 ones.  (This is called "two's complement"
  215. notation.)
  216.  
  217.    The negative integer, -5, is creating by subtracting 4 from -1.  In
  218. binary, the decimal integer 4 is 100.  Consequently, -5 looks like this:
  219.  
  220.      1111  1111 1111  1111 1111  1111 1011
  221.  
  222.    In this implementation, the largest 28-bit binary integer is the
  223. decimal integer 134,217,727.  In binary, it looks like this:
  224.  
  225.      0111  1111 1111  1111 1111  1111 1111
  226.  
  227.    Since the arithmetic functions do not check whether integers go
  228. outside their range, when you add 1 to 134,217,727, the value is the
  229. negative integer -134,217,728:
  230.  
  231.      (+ 1 134217727)
  232.           => -134217728
  233.           => 1000  0000 0000  0000 0000  0000 0000
  234.  
  235.    Many of the following functions accept markers for arguments as well
  236. as integers.  (*Note Markers::.)  More precisely, the actual arguments
  237. to such functions may be either integers or markers, which is why we
  238. often give these arguments the name INT-OR-MARKER.  When the argument
  239. value is a marker, its position value is used and its buffer is ignored.
  240.  
  241. 
  242. File: lispref.info,  Node: Float Basics,  Next: Predicates on Numbers,  Prev: Integer Basics,  Up: Numbers
  243.  
  244. Floating Point Basics
  245. =====================
  246.  
  247.    XEmacs supports floating point numbers.  The precise range of
  248. floating point numbers is machine-specific; it is the same as the range
  249. of the C data type `double' on the machine in question.
  250.  
  251.    The printed representation for floating point numbers requires either
  252. a decimal point (with at least one digit following), an exponent, or
  253. both.  For example, `1500.0', `15e2', `15.0e2', `1.5e3', and `.15e4'
  254. are five ways of writing a floating point number whose value is 1500.
  255. They are all equivalent.  You can also use a minus sign to write
  256. negative floating point numbers, as in `-1.0'.
  257.  
  258.    Most modern computers support the IEEE floating point standard, which
  259. provides for positive infinity and negative infinity as floating point
  260. values.  It also provides for a class of values called NaN or
  261. "not-a-number"; numerical functions return such values in cases where
  262. there is no correct answer.  For example, `(sqrt -1.0)' returns a NaN.
  263. For practical purposes, there's no significant difference between
  264. different NaN values in Emacs Lisp, and there's no rule for precisely
  265. which NaN value should be used in a particular case, so this manual
  266. doesn't try to distinguish them.  Emacs Lisp has no read syntax for NaNs
  267. or infinities; perhaps we should create a syntax in the future.
  268.  
  269.    You can use `logb' to extract the binary exponent of a floating
  270. point number (or estimate the logarithm of an integer):
  271.  
  272.  - Function: logb NUMBER
  273.      This function returns the binary exponent of NUMBER.  More
  274.      precisely, the value is the logarithm of NUMBER base 2, rounded
  275.      down to an integer.
  276.  
  277. 
  278. File: lispref.info,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Float Basics,  Up: Numbers
  279.  
  280. Type Predicates for Numbers
  281. ===========================
  282.  
  283.    The functions in this section test whether the argument is a number
  284. or whether it is a certain sort of number.  The functions `integerp'
  285. and `floatp' can take any type of Lisp object as argument (the
  286. predicates would not be of much use otherwise); but the `zerop'
  287. predicate requires a number as its argument.  See also
  288. `integer-or-marker-p' and `number-or-marker-p', in *Note Predicates on
  289. Markers::.
  290.  
  291.  - Function: floatp OBJECT
  292.      This predicate tests whether its argument is a floating point
  293.      number and returns `t' if so, `nil' otherwise.
  294.  
  295.      `floatp' does not exist in Emacs versions 18 and earlier.
  296.  
  297.  - Function: integerp OBJECT
  298.      This predicate tests whether its argument is an integer, and
  299.      returns `t' if so, `nil' otherwise.
  300.  
  301.  - Function: numberp OBJECT
  302.      This predicate tests whether its argument is a number (either
  303.      integer or floating point), and returns `t' if so, `nil' otherwise.
  304.  
  305.  - Function: wholenump OBJECT
  306.      The `wholenump' predicate (whose name comes from the phrase
  307.      "whole-number-p") tests to see whether its argument is a
  308.      nonnegative integer, and returns `t' if so, `nil' otherwise.  0 is
  309.      considered non-negative.
  310.  
  311.      `natnump' is an obsolete synonym for `wholenump'.
  312.  
  313.  - Function: zerop NUMBER
  314.      This predicate tests whether its argument is zero, and returns `t'
  315.      if so, `nil' otherwise.  The argument must be a number.
  316.  
  317.      These two forms are equivalent: `(zerop x)' == `(= x 0)'.
  318.  
  319. 
  320. File: lispref.info,  Node: Comparison of Numbers,  Next: Numeric Conversions,  Prev: Predicates on Numbers,  Up: Numbers
  321.  
  322. Comparison of Numbers
  323. =====================
  324.  
  325.    To test numbers for numerical equality, you should normally use `=',
  326. not `eq'.  There can be many distinct floating point number objects
  327. with the same numeric value.  If you use `eq' to compare them, then you
  328. test whether two values are the same *object*.  By contrast, `='
  329. compares only the numeric values of the objects.
  330.  
  331.    At present, each integer value has a unique Lisp object in Emacs
  332. Lisp.  Therefore, `eq' is equivalent `=' where integers are concerned.
  333. It is sometimes convenient to use `eq' for comparing an unknown value
  334. with an integer, because `eq' does not report an error if the unknown
  335. value is not a number--it accepts arguments of any type.  By contrast,
  336. `=' signals an error if the arguments are not numbers or markers.
  337. However, it is a good idea to use `=' if you can, even for comparing
  338. integers, just in case we change the representation of integers in a
  339. future XEmacs version.
  340.  
  341.    There is another wrinkle: because floating point arithmetic is not
  342. exact, it is often a bad idea to check for equality of two floating
  343. point values.  Usually it is better to test for approximate equality.
  344. Here's a function to do this:
  345.  
  346.      (defvar fuzz-factor 1.0e-6)
  347.      (defun approx-equal (x y)
  348.        (or (and (= x 0) (= y 0))
  349.            (< (/ (abs (- x y))
  350.                  (max (abs x) (abs y)))
  351.               fuzz-factor)))
  352.  
  353.      Common Lisp note: Comparing numbers in Common Lisp always requires
  354.      `=' because Common Lisp implements multi-word integers, and two
  355.      distinct integer objects can have the same numeric value.  Emacs
  356.      Lisp can have just one integer object for any given value because
  357.      it has a limited range of integer values.
  358.  
  359.  - Function: = NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  360.      This function tests whether its arguments are numerically equal,
  361.      and returns `t' if so, `nil' otherwise.
  362.  
  363.  - Function: /= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  364.      This function tests whether its arguments are numerically equal,
  365.      and returns `t' if they are not, and `nil' if they are.
  366.  
  367.  - Function: < NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  368.      This function tests whether its first argument is strictly less
  369.      than its second argument.  It returns `t' if so, `nil' otherwise.
  370.  
  371.  - Function: <= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  372.      This function tests whether its first argument is less than or
  373.      equal to its second argument.  It returns `t' if so, `nil'
  374.      otherwise.
  375.  
  376.  - Function: > NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  377.      This function tests whether its first argument is strictly greater
  378.      than its second argument.  It returns `t' if so, `nil' otherwise.
  379.  
  380.  - Function: >= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  381.      This function tests whether its first argument is greater than or
  382.      equal to its second argument.  It returns `t' if so, `nil'
  383.      otherwise.
  384.  
  385.  - Function: max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS
  386.      This function returns the largest of its arguments.
  387.  
  388.           (max 20)
  389.                => 20
  390.           (max 1 2.5)
  391.                => 2.5
  392.           (max 1 3 2.5)
  393.                => 3
  394.  
  395.  - Function: min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS
  396.      This function returns the smallest of its arguments.
  397.  
  398.           (min -4 1)
  399.                => -4
  400.  
  401. 
  402. File: lispref.info,  Node: Numeric Conversions,  Next: Arithmetic Operations,  Prev: Comparison of Numbers,  Up: Numbers
  403.  
  404. Numeric Conversions
  405. ===================
  406.  
  407.    To convert an integer to floating point, use the function `float'.
  408.  
  409.  - Function: float NUMBER
  410.      This returns NUMBER converted to floating point.  If NUMBER is
  411.      already a floating point number, `float' returns it unchanged.
  412.  
  413.    There are four functions to convert floating point numbers to
  414. integers; they differ in how they round.  These functions accept
  415. integer arguments also, and return such arguments unchanged.
  416.  
  417.  - Function: truncate NUMBER
  418.      This returns NUMBER, converted to an integer by rounding towards
  419.      zero.
  420.  
  421.  - Function: floor NUMBER &optional DIVISOR
  422.      This returns NUMBER, converted to an integer by rounding downward
  423.      (towards negative infinity).
  424.  
  425.      If DIVISOR is specified, NUMBER is divided by DIVISOR before the
  426.      floor is taken; this is the division operation that corresponds to
  427.      `mod'.  An `arith-error' results if DIVISOR is 0.
  428.  
  429.  - Function: ceiling NUMBER
  430.      This returns NUMBER, converted to an integer by rounding upward
  431.      (towards positive infinity).
  432.  
  433.  - Function: round NUMBER
  434.      This returns NUMBER, converted to an integer by rounding towards
  435.      the nearest integer.  Rounding a value equidistant between two
  436.      integers may choose the integer closer to zero, or it may prefer
  437.      an even integer, depending on your machine.
  438.  
  439. 
  440. File: lispref.info,  Node: Arithmetic Operations,  Next: Rounding Operations,  Prev: Numeric Conversions,  Up: Numbers
  441.  
  442. Arithmetic Operations
  443. =====================
  444.  
  445.    Emacs Lisp provides the traditional four arithmetic operations:
  446. addition, subtraction, multiplication, and division.  Remainder and
  447. modulus functions supplement the division functions.  The functions to
  448. add or subtract 1 are provided because they are traditional in Lisp and
  449. commonly used.
  450.  
  451.    All of these functions except `%' return a floating point value if
  452. any argument is floating.
  453.  
  454.    It is important to note that in Emacs Lisp, arithmetic functions do
  455. not check for overflow.  Thus `(1+ 134217727)' may evaluate to
  456. -134217728, depending on your hardware.
  457.  
  458.  - Function: 1+ NUMBER-OR-MARKER
  459.      This function returns NUMBER-OR-MARKER plus 1.  For example,
  460.  
  461.           (setq foo 4)
  462.                => 4
  463.           (1+ foo)
  464.                => 5
  465.  
  466.      This function is not analogous to the C operator `++'--it does not
  467.      increment a variable.  It just computes a sum.  Thus, if we
  468.      continue,
  469.  
  470.           foo
  471.                => 4
  472.  
  473.      If you want to increment the variable, you must use `setq', like
  474.      this:
  475.  
  476.           (setq foo (1+ foo))
  477.                => 5
  478.  
  479.  - Function: 1- NUMBER-OR-MARKER
  480.      This function returns NUMBER-OR-MARKER minus 1.
  481.  
  482.  - Function: abs NUMBER
  483.      This returns the absolute value of NUMBER.
  484.  
  485.  - Function: + &rest NUMBERS-OR-MARKERS
  486.      This function adds its arguments together.  When given no
  487.      arguments, `+' returns 0.
  488.  
  489.           (+)
  490.                => 0
  491.           (+ 1)
  492.                => 1
  493.           (+ 1 2 3 4)
  494.                => 10
  495.  
  496.  - Function: - &optional NUMBER-OR-MARKER &rest OTHER-NUMBERS-OR-MARKERS
  497.      The `-' function serves two purposes: negation and subtraction.
  498.      When `-' has a single argument, the value is the negative of the
  499.      argument.  When there are multiple arguments, `-' subtracts each of
  500.      the OTHER-NUMBERS-OR-MARKERS from NUMBER-OR-MARKER, cumulatively.
  501.      If there are no arguments, the result is 0.
  502.  
  503.           (- 10 1 2 3 4)
  504.                => 0
  505.           (- 10)
  506.                => -10
  507.           (-)
  508.                => 0
  509.  
  510.  - Function: * &rest NUMBERS-OR-MARKERS
  511.      This function multiplies its arguments together, and returns the
  512.      product.  When given no arguments, `*' returns 1.
  513.  
  514.           (*)
  515.                => 1
  516.           (* 1)
  517.                => 1
  518.           (* 1 2 3 4)
  519.                => 24
  520.  
  521.  - Function: / DIVIDEND DIVISOR &rest DIVISORS
  522.      This function divides DIVIDEND by DIVISOR and returns the
  523.      quotient.  If there are additional arguments DIVISORS, then it
  524.      divides DIVIDEND by each divisor in turn.  Each argument may be a
  525.      number or a marker.
  526.  
  527.      If all the arguments are integers, then the result is an integer
  528.      too.  This means the result has to be rounded.  On most machines,
  529.      the result is rounded towards zero after each division, but some
  530.      machines may round differently with negative arguments.  This is
  531.      because the Lisp function `/' is implemented using the C division
  532.      operator, which also permits machine-dependent rounding.  As a
  533.      practical matter, all known machines round in the standard fashion.
  534.  
  535.      If you divide by 0, an `arith-error' error is signaled.  (*Note
  536.      Errors::.)
  537.  
  538.           (/ 6 2)
  539.                => 3
  540.           (/ 5 2)
  541.                => 2
  542.           (/ 25 3 2)
  543.                => 4
  544.           (/ -17 6)
  545.                => -2
  546.  
  547.      The result of `(/ -17 6)' could in principle be -3 on some
  548.      machines.
  549.  
  550.  - Function: % DIVIDEND DIVISOR
  551.      This function returns the integer remainder after division of
  552.      DIVIDEND by DIVISOR.  The arguments must be integers or markers.
  553.  
  554.      For negative arguments, the remainder is in principle
  555.      machine-dependent since the quotient is; but in practice, all
  556.      known machines behave alike.
  557.  
  558.      An `arith-error' results if DIVISOR is 0.
  559.  
  560.           (% 9 4)
  561.                => 1
  562.           (% -9 4)
  563.                => -1
  564.           (% 9 -4)
  565.                => 1
  566.           (% -9 -4)
  567.                => -1
  568.  
  569.      For any two integers DIVIDEND and DIVISOR,
  570.  
  571.           (+ (% DIVIDEND DIVISOR)
  572.              (* (/ DIVIDEND DIVISOR) DIVISOR))
  573.  
  574.      always equals DIVIDEND.
  575.  
  576.  - Function: mod DIVIDEND DIVISOR
  577.      This function returns the value of DIVIDEND modulo DIVISOR; in
  578.      other words, the remainder after division of DIVIDEND by DIVISOR,
  579.      but with the same sign as DIVISOR.  The arguments must be numbers
  580.      or markers.
  581.  
  582.      Unlike `%', `mod' returns a well-defined result for negative
  583.      arguments.  It also permits floating point arguments; it rounds the
  584.      quotient downward (towards minus infinity) to an integer, and uses
  585.      that quotient to compute the remainder.
  586.  
  587.      An `arith-error' results if DIVISOR is 0.
  588.  
  589.           (mod 9 4)
  590.                => 1
  591.           (mod -9 4)
  592.                => 3
  593.           (mod 9 -4)
  594.                => -3
  595.           (mod -9 -4)
  596.                => -1
  597.           (mod 5.5 2.5)
  598.                => .5
  599.  
  600.      For any two numbers DIVIDEND and DIVISOR,
  601.  
  602.           (+ (mod DIVIDEND DIVISOR)
  603.              (* (floor DIVIDEND DIVISOR) DIVISOR))
  604.  
  605.      always equals DIVIDEND, subject to rounding error if either
  606.      argument is floating point.  For `floor', see *Note Numeric
  607.      Conversions::.
  608.  
  609. 
  610. File: lispref.info,  Node: Rounding Operations,  Next: Bitwise Operations,  Prev: Arithmetic Operations,  Up: Numbers
  611.  
  612. Rounding Operations
  613. ===================
  614.  
  615.    The functions `ffloor', `fceiling', `fround' and `ftruncate' take a
  616. floating point argument and return a floating point result whose value
  617. is a nearby integer.  `ffloor' returns the nearest integer below;
  618. `fceiling', the nearest integer above; `ftruncate', the nearest integer
  619. in the direction towards zero; `fround', the nearest integer.
  620.  
  621.  - Function: ffloor FLOAT
  622.      This function rounds FLOAT to the next lower integral value, and
  623.      returns that value as a floating point number.
  624.  
  625.  - Function: fceiling FLOAT
  626.      This function rounds FLOAT to the next higher integral value, and
  627.      returns that value as a floating point number.
  628.  
  629.  - Function: ftruncate FLOAT
  630.      This function rounds FLOAT towards zero to an integral value, and
  631.      returns that value as a floating point number.
  632.  
  633.  - Function: fround FLOAT
  634.      This function rounds FLOAT to the nearest integral value, and
  635.      returns that value as a floating point number.
  636.  
  637. 
  638. File: lispref.info,  Node: Bitwise Operations,  Next: Math Functions,  Prev: Rounding Operations,  Up: Numbers
  639.  
  640. Bitwise Operations on Integers
  641. ==============================
  642.  
  643.    In a computer, an integer is represented as a binary number, a
  644. sequence of "bits" (digits which are either zero or one).  A bitwise
  645. operation acts on the individual bits of such a sequence.  For example,
  646. "shifting" moves the whole sequence left or right one or more places,
  647. reproducing the same pattern "moved over".
  648.  
  649.    The bitwise operations in Emacs Lisp apply only to integers.
  650.  
  651.  - Function: lsh INTEGER1 COUNT
  652.      `lsh', which is an abbreviation for "logical shift", shifts the
  653.      bits in INTEGER1 to the left COUNT places, or to the right if
  654.      COUNT is negative, bringing zeros into the vacated bits.  If COUNT
  655.      is negative, `lsh' shifts zeros into the leftmost
  656.      (most-significant) bit, producing a positive result even if
  657.      INTEGER1 is negative.  Contrast this with `ash', below.
  658.  
  659.      Here are two examples of `lsh', shifting a pattern of bits one
  660.      place to the left.  We show only the low-order eight bits of the
  661.      binary pattern; the rest are all zero.
  662.  
  663.           (lsh 5 1)
  664.                => 10
  665.           ;; Decimal 5 becomes decimal 10.
  666.           00000101 => 00001010
  667.           
  668.           (lsh 7 1)
  669.                => 14
  670.           ;; Decimal 7 becomes decimal 14.
  671.           00000111 => 00001110
  672.  
  673.      As the examples illustrate, shifting the pattern of bits one place
  674.      to the left produces a number that is twice the value of the
  675.      previous number.
  676.  
  677.      Shifting a pattern of bits two places to the left produces results
  678.      like this (with 8-bit binary numbers):
  679.  
  680.           (lsh 3 2)
  681.                => 12
  682.           ;; Decimal 3 becomes decimal 12.
  683.           00000011 => 00001100
  684.  
  685.      On the other hand, shifting one place to the right looks like this:
  686.  
  687.           (lsh 6 -1)
  688.                => 3
  689.           ;; Decimal 6 becomes decimal 3.
  690.           00000110 => 00000011
  691.           
  692.           (lsh 5 -1)
  693.                => 2
  694.           ;; Decimal 5 becomes decimal 2.
  695.           00000101 => 00000010
  696.  
  697.      As the example illustrates, shifting one place to the right
  698.      divides the value of a positive integer by two, rounding downward.
  699.  
  700.      The function `lsh', like all Emacs Lisp arithmetic functions, does
  701.      not check for overflow, so shifting left can discard significant
  702.      bits and change the sign of the number.  For example, left shifting
  703.      134,217,727 produces -2 on a 28-bit machine:
  704.  
  705.           (lsh 134217727 1)          ; left shift
  706.                => -2
  707.  
  708.      In binary, in the 28-bit implementation, the argument looks like
  709.      this:
  710.  
  711.           ;; Decimal 134,217,727
  712.           0111  1111 1111  1111 1111  1111 1111
  713.  
  714.      which becomes the following when left shifted:
  715.  
  716.           ;; Decimal -2
  717.           1111  1111 1111  1111 1111  1111 1110
  718.  
  719.  - Function: ash INTEGER1 COUNT
  720.      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the left
  721.      COUNT places, or to the right if COUNT is negative.
  722.  
  723.      `ash' gives the same results as `lsh' except when INTEGER1 and
  724.      COUNT are both negative.  In that case, `ash' puts ones in the
  725.      empty bit positions on the left, while `lsh' puts zeros in those
  726.      bit positions.
  727.  
  728.      Thus, with `ash', shifting the pattern of bits one place to the
  729.      right looks like this:
  730.  
  731.           (ash -6 -1) => -3
  732.           ;; Decimal -6 becomes decimal -3.
  733.           1111  1111 1111  1111 1111  1111 1010
  734.                =>
  735.           1111  1111 1111  1111 1111  1111 1101
  736.  
  737.      In contrast, shifting the pattern of bits one place to the right
  738.      with `lsh' looks like this:
  739.  
  740.           (lsh -6 -1) => 134217725
  741.           ;; Decimal -6 becomes decimal 134,217,725.
  742.           1111  1111 1111  1111 1111  1111 1010
  743.                =>
  744.           0111  1111 1111  1111 1111  1111 1101
  745.  
  746.      Here are other examples:
  747.  
  748.           ;               28-bit binary values
  749.           
  750.           (lsh 5 2)          ;   5  =  0000  0000 0000  0000 0000  0000 0101
  751.                => 20         ;      =  0000  0000 0000  0000 0000  0001 0100
  752.  
  753.           (ash 5 2)
  754.                => 20
  755.           (lsh -5 2)         ;  -5  =  1111  1111 1111  1111 1111  1111 1011
  756.                => -20        ;      =  1111  1111 1111  1111 1111  1110 1100
  757.           (ash -5 2)
  758.                => -20
  759.  
  760.           (lsh 5 -2)         ;   5  =  0000  0000 0000  0000 0000  0000 0101
  761.                => 1          ;      =  0000  0000 0000  0000 0000  0000 0001
  762.  
  763.           (ash 5 -2)
  764.                => 1
  765.  
  766.           (lsh -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
  767.                => 4194302    ;      =  0011  1111 1111  1111 1111  1111 1110
  768.  
  769.           (ash -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
  770.                => -2         ;      =  1111  1111 1111  1111 1111  1111 1110
  771.  
  772.  - Function: logand &rest INTS-OR-MARKERS
  773.      This function returns the "logical and" of the arguments: the Nth
  774.      bit is set in the result if, and only if, the Nth bit is set in
  775.      all the arguments.  ("Set" means that the value of the bit is 1
  776.      rather than 0.)
  777.  
  778.      For example, using 4-bit binary numbers, the "logical and" of 13
  779.      and 12 is 12: 1101 combined with 1100 produces 1100.  In both the
  780.      binary numbers, the leftmost two bits are set (i.e., they are
  781.      1's), so the leftmost two bits of the returned value are set.
  782.      However, for the rightmost two bits, each is zero in at least one
  783.      of the arguments, so the rightmost two bits of the returned value
  784.      are 0's.
  785.  
  786.      Therefore,
  787.  
  788.           (logand 13 12)
  789.                => 12
  790.  
  791.      If `logand' is not passed any argument, it returns a value of -1.
  792.      This number is an identity element for `logand' because its binary
  793.      representation consists entirely of ones.  If `logand' is passed
  794.      just one argument, it returns that argument.
  795.  
  796.           ;                28-bit binary values
  797.           
  798.           (logand 14 13)     ; 14  =  0000  0000 0000  0000 0000  0000 1110
  799.                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
  800.                => 12         ; 12  =  0000  0000 0000  0000 0000  0000 1100
  801.  
  802.           (logand 14 13 4)   ; 14  =  0000  0000 0000  0000 0000  0000 1110
  803.                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
  804.                              ;  4  =  0000  0000 0000  0000 0000  0000 0100
  805.                => 4          ;  4  =  0000  0000 0000  0000 0000  0000 0100
  806.  
  807.           (logand)
  808.                => -1         ; -1  =  1111  1111 1111  1111 1111  1111 1111
  809.  
  810.  - Function: logior &rest INTS-OR-MARKERS
  811.      This function returns the "inclusive or" of its arguments: the Nth
  812.      bit is set in the result if, and only if, the Nth bit is set in at
  813.      least one of the arguments.  If there are no arguments, the result
  814.      is zero, which is an identity element for this operation.  If
  815.      `logior' is passed just one argument, it returns that argument.
  816.  
  817.           ;               28-bit binary values
  818.           
  819.           (logior 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
  820.                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
  821.                => 13         ; 13  =  0000  0000 0000  0000 0000  0000 1101
  822.  
  823.           (logior 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
  824.                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
  825.                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
  826.                => 15         ; 15  =  0000  0000 0000  0000 0000  0000 1111
  827.  
  828.  - Function: logxor &rest INTS-OR-MARKERS
  829.      This function returns the "exclusive or" of its arguments: the Nth
  830.      bit is set in the result if, and only if, the Nth bit is set in an
  831.      odd number of the arguments.  If there are no arguments, the
  832.      result is 0, which is an identity element for this operation.  If
  833.      `logxor' is passed just one argument, it returns that argument.
  834.  
  835.           ;               28-bit binary values
  836.           
  837.           (logxor 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
  838.                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
  839.                => 9          ;  9  =  0000  0000 0000  0000 0000  0000 1001
  840.  
  841.           (logxor 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
  842.                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
  843.                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
  844.                => 14         ; 14  =  0000  0000 0000  0000 0000  0000 1110
  845.  
  846.  - Function: lognot INTEGER
  847.      This function returns the logical complement of its argument: the
  848.      Nth bit is one in the result if, and only if, the Nth bit is zero
  849.      in INTEGER, and vice-versa.
  850.  
  851.           (lognot 5)
  852.                => -6
  853.           ;;  5  =  0000  0000 0000  0000 0000  0000 0101
  854.           ;; becomes
  855.           ;; -6  =  1111  1111 1111  1111 1111  1111 1010
  856.  
  857. 
  858. File: lispref.info,  Node: Math Functions,  Next: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
  859.  
  860. Standard Mathematical Functions
  861. ===============================
  862.  
  863.    These mathematical functions are available if floating point is
  864. supported.  They allow integers as well as floating point numbers as
  865. arguments.
  866.  
  867.  - Function: sin ARG
  868.  - Function: cos ARG
  869.  - Function: tan ARG
  870.      These are the ordinary trigonometric functions, with argument
  871.      measured in radians.
  872.  
  873.  - Function: asin ARG
  874.      The value of `(asin ARG)' is a number between -pi/2 and pi/2
  875.      (inclusive) whose sine is ARG; if, however, ARG is out of range
  876.      (outside [-1, 1]), then the result is a NaN.
  877.  
  878.  - Function: acos ARG
  879.      The value of `(acos ARG)' is a number between 0 and pi (inclusive)
  880.      whose cosine is ARG; if, however, ARG is out of range (outside
  881.      [-1, 1]), then the result is a NaN.
  882.  
  883.  - Function: atan ARG
  884.      The value of `(atan ARG)' is a number between -pi/2 and pi/2
  885.      (exclusive) whose tangent is ARG.
  886.  
  887.  - Function: exp ARG
  888.      This is the exponential function; it returns e to the power ARG.
  889.      e is a fundamental mathematical constant also called the base of
  890.      natural logarithms.
  891.  
  892.  - Function: log ARG &optional BASE
  893.      This function returns the logarithm of ARG, with base BASE.  If
  894.      you don't specify BASE, the base E is used.  If ARG is negative,
  895.      the result is a NaN.
  896.  
  897.  - Function: log10 ARG
  898.      This function returns the logarithm of ARG, with base 10.  If ARG
  899.      is negative, the result is a NaN.  `(log10 X)' == `(log X 10)', at
  900.      least approximately.
  901.  
  902.  - Function: expt X Y
  903.      This function returns X raised to power Y.  If both arguments are
  904.      integers and Y is positive, the result is an integer; in this
  905.      case, it is truncated to fit the range of possible integer values.
  906.  
  907.  - Function: sqrt ARG
  908.      This returns the square root of ARG.  If ARG is negative, the
  909.      value is a NaN.
  910.  
  911. 
  912. File: lispref.info,  Node: Random Numbers,  Prev: Math Functions,  Up: Numbers
  913.  
  914. Random Numbers
  915. ==============
  916.  
  917.    A deterministic computer program cannot generate true random numbers.
  918. For most purposes, "pseudo-random numbers" suffice.  A series of
  919. pseudo-random numbers is generated in a deterministic fashion.  The
  920. numbers are not truly random, but they have certain properties that
  921. mimic a random series.  For example, all possible values occur equally
  922. often in a pseudo-random series.
  923.  
  924.    In XEmacs, pseudo-random numbers are generated from a "seed" number.
  925. Starting from any given seed, the `random' function always generates
  926. the same sequence of numbers.  XEmacs always starts with the same seed
  927. value, so the sequence of values of `random' is actually the same in
  928. each XEmacs run!  For example, in one operating system, the first call
  929. to `(random)' after you start Emacs always returns -1457731, and the
  930. second one always returns -7692030.  This repeatability is helpful for
  931. debugging.
  932.  
  933.    If you want truly unpredictable random numbers, execute `(random
  934. t)'.  This chooses a new seed based on the current time of day and on
  935. XEmacs's process ID number.
  936.  
  937.  - Function: random &optional LIMIT
  938.      This function returns a pseudo-random integer.  Repeated calls
  939.      return a series of pseudo-random integers.
  940.  
  941.      If LIMIT is a positive integer, the value is chosen to be
  942.      nonnegative and less than LIMIT.
  943.  
  944.      If LIMIT is `t', it means to choose a new seed based on the
  945.      current time of day and on XEmacs's process ID number.
  946.  
  947.      On some machines, any integer representable in Lisp may be the
  948.      result of `random'.  On other machines, the result can never be
  949.      larger than a certain maximum or less than a certain (negative)
  950.      minimum.
  951.  
  952. 
  953. File: lispref.info,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
  954.  
  955. Strings and Characters
  956. **********************
  957.  
  958.    A string in Emacs Lisp is an array that contains an ordered sequence
  959. of characters.  Strings are used as names of symbols, buffers, and
  960. files, to send messages to users, to hold text being copied between
  961. buffers, and for many other purposes.  Because strings are so important,
  962. Emacs Lisp has many functions expressly for manipulating them.  Emacs
  963. Lisp programs use strings more often than individual characters.
  964.  
  965. * Menu:
  966.  
  967. * Basics: String Basics.      Basic properties of strings and characters.
  968. * Predicates for Strings::    Testing whether an object is a string or char.
  969. * Creating Strings::          Functions to allocate new strings.
  970. * Text Comparison::           Comparing characters or strings.
  971. * String Conversion::         Converting characters or strings and vice versa.
  972. * Formatting Strings::        `format': XEmacs's analog of `printf'.
  973. * Character Case::            Case conversion functions.
  974. * Case Table::              Customizing case conversion.
  975.  
  976. 
  977. File: lispref.info,  Node: String Basics,  Next: Predicates for Strings,  Up: Strings and Characters
  978.  
  979. String and Character Basics
  980. ===========================
  981.  
  982.    Strings in Emacs Lisp are arrays that contain an ordered sequence of
  983. characters.  Characters are represented in Emacs Lisp as integers;
  984. whether an integer was intended as a character or not is determined only
  985. by how it is used.  Thus, strings really contain integers.
  986.  
  987.    The length of a string (like any array) is fixed and independent of
  988. the string contents, and cannot be altered.  Strings in Lisp are *not*
  989. terminated by a distinguished character code.  (By contrast, strings in
  990. C are terminated by a character with ASCII code 0.) This means that any
  991. character, including the null character (ASCII code 0), is a valid
  992. element of a string.
  993.  
  994.    Since strings are considered arrays, you can operate on them with the
  995. general array functions.  (*Note Sequences Arrays Vectors::.)  For
  996. example, you can access or change individual characters in a string
  997. using the functions `aref' and `aset' (*note Array Functions::.).
  998.  
  999.    Each character in a string is stored in a single byte.  Therefore,
  1000. numbers not in the range 0 to 255 are truncated when stored into a
  1001. string.  This means that a string takes up much less memory than a
  1002. vector of the same length.
  1003.  
  1004.    Sometimes key sequences are represented as strings.  When a string is
  1005. a key sequence, string elements in the range 128 to 255 represent meta
  1006. characters (which are extremely large integers) rather than keyboard
  1007. events in the range 128 to 255.
  1008.  
  1009.    Strings cannot hold characters that have the hyper, super or alt
  1010. modifiers; they can hold ASCII control characters, but no other control
  1011. characters.  They do not distinguish case in ASCII control characters.
  1012. *Note Character Type::, for more information about representation of
  1013. meta and other modifiers for keyboard input characters.
  1014.  
  1015.    Strings are useful for holding regular expressions.  You can also
  1016. match regular expressions against strings (*note Regexp Search::.).  The
  1017. functions `match-string' (*note Simple Match Data::.) and
  1018. `replace-match' (*note Replacing Match::.) are useful for decomposing
  1019. and modifying strings based on regular expression matching.
  1020.  
  1021.    Like a buffer, a string can contain extents in it.  These extents are
  1022. created when a function such as `buffer-substring' is called on a
  1023. region with duplicable extents in it.  When the string is inserted into
  1024. a buffer, the extents are inserted along with it.  *Note Duplicable
  1025. Extents::.
  1026.  
  1027.    *Note Text::, for information about functions that display strings or
  1028. copy them into buffers.  *Note Character Type::, and *Note String
  1029. Type::, for information about the syntax of characters and strings.
  1030.  
  1031. 
  1032. File: lispref.info,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: String Basics,  Up: Strings and Characters
  1033.  
  1034. The Predicates for Strings
  1035. ==========================
  1036.  
  1037.    For more information about general sequence and array predicates,
  1038. see *Note Sequences Arrays Vectors::, and *Note Arrays::.
  1039.  
  1040.  - Function: stringp OBJECT
  1041.      This function returns `t' if OBJECT is a string, `nil' otherwise.
  1042.  
  1043.  - Function: char-or-string-p OBJECT
  1044.      This function returns `t' if OBJECT is a string or a character
  1045.      (i.e., an integer), `nil' otherwise.
  1046.  
  1047. 
  1048. File: lispref.info,  Node: Creating Strings,  Next: Text Comparison,  Prev: Predicates for Strings,  Up: Strings and Characters
  1049.  
  1050. Creating Strings
  1051. ================
  1052.  
  1053.    The following functions create strings, either from scratch, or by
  1054. putting strings together, or by taking them apart.
  1055.  
  1056.  - Function: make-string COUNT CHARACTER
  1057.      This function returns a string made up of COUNT repetitions of
  1058.      CHARACTER.  If COUNT is negative, an error is signaled.
  1059.  
  1060.           (make-string 5 ?x)
  1061.                => "xxxxx"
  1062.           (make-string 0 ?x)
  1063.                => ""
  1064.  
  1065.      Other functions to compare with this one include `char-to-string'
  1066.      (*note String Conversion::.), `make-vector' (*note Vectors::.), and
  1067.      `make-list' (*note Building Lists::.).
  1068.  
  1069.  - Function: substring STRING START &optional END
  1070.      This function returns a new string which consists of those
  1071.      characters from STRING in the range from (and including) the
  1072.      character at the index START up to (but excluding) the character
  1073.      at the index END.  The first character is at index zero.
  1074.  
  1075.           (substring "abcdefg" 0 3)
  1076.                => "abc"
  1077.  
  1078.      Here the index for `a' is 0, the index for `b' is 1, and the index
  1079.      for `c' is 2.  Thus, three letters, `abc', are copied from the
  1080.      string `"abcdefg"'.  The index 3 marks the character position up
  1081.      to which the substring is copied.  The character whose index is 3
  1082.      is actually the fourth character in the string.
  1083.  
  1084.      A negative number counts from the end of the string, so that -1
  1085.      signifies the index of the last character of the string.  For
  1086.      example:
  1087.  
  1088.           (substring "abcdefg" -3 -1)
  1089.                => "ef"
  1090.  
  1091.      In this example, the index for `e' is -3, the index for `f' is -2,
  1092.      and the index for `g' is -1.  Therefore, `e' and `f' are included,
  1093.      and `g' is excluded.
  1094.  
  1095.      When `nil' is used as an index, it stands for the length of the
  1096.      string.  Thus,
  1097.  
  1098.           (substring "abcdefg" -3 nil)
  1099.                => "efg"
  1100.  
  1101.      Omitting the argument END is equivalent to specifying `nil'.  It
  1102.      follows that `(substring STRING 0)' returns a copy of all of
  1103.      STRING.
  1104.  
  1105.           (substring "abcdefg" 0)
  1106.                => "abcdefg"
  1107.  
  1108.      But we recommend `copy-sequence' for this purpose (*note Sequence
  1109.      Functions::.).
  1110.  
  1111.      If the characters copied from STRING have text properties, the
  1112.      properties are copied into the new string also.  *Note Text
  1113.      Properties::.
  1114.  
  1115.      A `wrong-type-argument' error is signaled if either START or END
  1116.      is not an integer or `nil'.  An `args-out-of-range' error is
  1117.      signaled if START indicates a character following END, or if
  1118.      either integer is out of range for STRING.
  1119.  
  1120.      Contrast this function with `buffer-substring' (*note Buffer
  1121.      Contents::.), which returns a string containing a portion of the
  1122.      text in the current buffer.  The beginning of a string is at index
  1123.      0, but the beginning of a buffer is at index 1.
  1124.  
  1125.  - Function: concat &rest SEQUENCES
  1126.      This function returns a new string consisting of the characters in
  1127.      the arguments passed to it (along with their text properties, if
  1128.      any).  The arguments may be strings, lists of numbers, or vectors
  1129.      of numbers; they are not themselves changed.  If `concat' receives
  1130.      no arguments, it returns an empty string.
  1131.  
  1132.           (concat "abc" "-def")
  1133.                => "abc-def"
  1134.           (concat "abc" (list 120 (+ 256 121)) [122])
  1135.                => "abcxyz"
  1136.           ;; `nil' is an empty sequence.
  1137.           (concat "abc" nil "-def")
  1138.                => "abc-def"
  1139.           (concat "The " "quick brown " "fox.")
  1140.                => "The quick brown fox."
  1141.           (concat)
  1142.                => ""
  1143.  
  1144.      The second example above shows how characters stored in strings are
  1145.      taken modulo 256.  In other words, each character in the string is
  1146.      stored in one byte.
  1147.  
  1148.      The `concat' function always constructs a new string that is not
  1149.      `eq' to any existing string.
  1150.  
  1151.      When an argument is an integer (not a sequence of integers), it is
  1152.      converted to a string of digits making up the decimal printed
  1153.      representation of the integer.  *Don't use this feature; we plan
  1154.      to eliminate it.  If you already use this feature, change your
  1155.      programs now!*  The proper way to convert an integer to a decimal
  1156.      number in this way is with `format' (*note Formatting Strings::.)
  1157.      or `number-to-string' (*note String Conversion::.).
  1158.  
  1159.           (concat 137)
  1160.                => "137"
  1161.           (concat 54 321)
  1162.                => "54321"
  1163.  
  1164.      For information about other concatenation functions, see the
  1165.      description of `mapconcat' in *Note Mapping Functions::, `vconcat'
  1166.      in *Note Vectors::, and `append' in *Note Building Lists::.
  1167.  
  1168. 
  1169. File: lispref.info,  Node: Text Comparison,  Next: String Conversion,  Prev: Creating Strings,  Up: Strings and Characters
  1170.  
  1171. Comparison of Characters and Strings
  1172. ====================================
  1173.  
  1174.  - Function: char-equal CHARACTER1 CHARACTER2
  1175.      This function returns `t' if the arguments represent the same
  1176.      character, `nil' otherwise.  This function ignores differences in
  1177.      case if `case-fold-search' is non-`nil'.
  1178.  
  1179.           (char-equal ?x ?x)
  1180.                => t
  1181.           (char-to-string (+ 256 ?x))
  1182.                => "x"
  1183.           (char-equal ?x  (+ 256 ?x))
  1184.                => t
  1185.  
  1186.  - Function: string= STRING1 STRING2
  1187.      This function returns `t' if the characters of the two strings
  1188.      match exactly; case is significant.
  1189.  
  1190.           (string= "abc" "abc")
  1191.                => t
  1192.           (string= "abc" "ABC")
  1193.                => nil
  1194.           (string= "ab" "ABC")
  1195.                => nil
  1196.  
  1197.      The function `string=' ignores the text properties of the two
  1198.      strings.  To compare strings in a way that compares their text
  1199.      properties also, use `equal' (*note Equality Predicates::.).
  1200.  
  1201.  - Function: string-equal STRING1 STRING2
  1202.      `string-equal' is another name for `string='.
  1203.  
  1204.  - Function: string< STRING1 STRING2
  1205.      This function compares two strings a character at a time.  First it
  1206.      scans both the strings at once to find the first pair of
  1207.      corresponding characters that do not match.  If the lesser
  1208.      character of those two is the character from STRING1, then STRING1
  1209.      is less, and this function returns `t'.  If the lesser character
  1210.      is the one from STRING2, then STRING1 is greater, and this
  1211.      function returns `nil'.  If the two strings match entirely, the
  1212.      value is `nil'.
  1213.  
  1214.      Pairs of characters are compared by their ASCII codes.  Keep in
  1215.      mind that lower case letters have higher numeric values in the
  1216.      ASCII character set than their upper case counterparts; numbers and
  1217.      many punctuation characters have a lower numeric value than upper
  1218.      case letters.
  1219.  
  1220.           (string< "abc" "abd")
  1221.                => t
  1222.           (string< "abd" "abc")
  1223.                => nil
  1224.           (string< "123" "abc")
  1225.                => t
  1226.  
  1227.      When the strings have different lengths, and they match up to the
  1228.      length of STRING1, then the result is `t'.  If they match up to
  1229.      the length of STRING2, the result is `nil'.  A string of no
  1230.      characters is less than any other string.
  1231.  
  1232.           (string< "" "abc")
  1233.                => t
  1234.           (string< "ab" "abc")
  1235.                => t
  1236.           (string< "abc" "")
  1237.                => nil
  1238.           (string< "abc" "ab")
  1239.                => nil
  1240.           (string< "" "")
  1241.                => nil
  1242.  
  1243.  - Function: string-lessp STRING1 STRING2
  1244.      `string-lessp' is another name for `string<'.
  1245.  
  1246.    See also `compare-buffer-substrings' in *Note Comparing Text::, for
  1247. a way to compare text in buffers.  The function `string-match', which
  1248. matches a regular expression against a string, can be used for a kind
  1249. of string comparison; see *Note Regexp Search::.
  1250.  
  1251. 
  1252. File: lispref.info,  Node: String Conversion,  Next: Formatting Strings,  Prev: Text Comparison,  Up: Strings and Characters
  1253.  
  1254. Conversion of Characters and Strings
  1255. ====================================
  1256.  
  1257.    This section describes functions for conversions between characters,
  1258. strings and integers.  `format' and `prin1-to-string' (*note Output
  1259. Functions::.) can also convert Lisp objects into strings.
  1260. `read-from-string' (*note Input Functions::.) can "convert" a string
  1261. representation of a Lisp object into an object.
  1262.  
  1263.    *Note Documentation::, for functions that produce textual
  1264. descriptions of text characters and general input events
  1265. (`single-key-description' and `text-char-description').  These
  1266. functions are used primarily for making help messages.
  1267.  
  1268.  - Function: char-to-string CHARACTER
  1269.      This function returns a new string with a length of one character.
  1270.      The value of CHARACTER, modulo 256, is used to initialize the
  1271.      element of the string.
  1272.  
  1273.      This function is similar to `make-string' with an integer argument
  1274.      of 1.  (*Note Creating Strings::.)  This conversion can also be
  1275.      done with `format' using the `%c' format specification.  (*Note
  1276.      Formatting Strings::.)
  1277.  
  1278.           (char-to-string ?x)
  1279.                => "x"
  1280.           (char-to-string (+ 256 ?x))
  1281.                => "x"
  1282.           (make-string 1 ?x)
  1283.                => "x"
  1284.  
  1285.  - Function: string-to-char STRING
  1286.      This function returns the first character in STRING.  If the
  1287.      string is empty, the function returns 0.  The value is also 0 when
  1288.      the first character of STRING is the null character, ASCII code 0.
  1289.  
  1290.           (string-to-char "ABC")
  1291.                => 65
  1292.           (string-to-char "xyz")
  1293.                => 120
  1294.           (string-to-char "")
  1295.                => 0
  1296.           (string-to-char "\000")
  1297.                => 0
  1298.  
  1299.      This function may be eliminated in the future if it does not seem
  1300.      useful enough to retain.
  1301.  
  1302.  - Function: number-to-string NUMBER
  1303.      This function returns a string consisting of the printed
  1304.      representation of NUMBER, which may be an integer or a floating
  1305.      point number.  The value starts with a sign if the argument is
  1306.      negative.
  1307.  
  1308.           (number-to-string 256)
  1309.                => "256"
  1310.           (number-to-string -23)
  1311.                => "-23"
  1312.           (number-to-string -23.5)
  1313.                => "-23.5"
  1314.  
  1315.      `int-to-string' is a semi-obsolete alias for this function.
  1316.  
  1317.      See also the function `format' in *Note Formatting Strings::.
  1318.  
  1319.  - Function: string-to-number STRING
  1320.      This function returns the numeric value of the characters in
  1321.      STRING, read in base ten.  It skips spaces and tabs at the
  1322.      beginning of STRING, then reads as much of STRING as it can
  1323.      interpret as a number.  (On some systems it ignores other
  1324.      whitespace at the beginning, not just spaces and tabs.)  If the
  1325.      first character after the ignored whitespace is not a digit or a
  1326.      minus sign, this function returns 0.
  1327.  
  1328.           (string-to-number "256")
  1329.                => 256
  1330.           (string-to-number "25 is a perfect square.")
  1331.                => 25
  1332.           (string-to-number "X256")
  1333.                => 0
  1334.           (string-to-number "-4.5")
  1335.                => -4.5
  1336.  
  1337.      `string-to-int' is an obsolete alias for this function.
  1338.  
  1339.